﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace ClassAdd
{
    class ViewClassDescription
    {
        public void writeClass (String className, String nameSpace, String pathToWrite, String pathToTemplate, String tableName)
        {
            Directory.CreateDirectory(pathToWrite + "\\View\\" + className);
            String maskString = File.ReadAllText(pathToTemplate + "\\Views\\Edit.txt");
            maskString = maskString.Replace("NAMESPACE", nameSpace);
            maskString = maskString.Replace("TABLENAME", tableName);

            try
            {
                File.WriteAllText(pathToWrite + "\\View\\" + className + "\\Edit.aspx", maskString.Replace("MASK", className));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            Directory.CreateDirectory(pathToWrite + "\\View\\" + className);
            String maskString2 = File.ReadAllText(pathToTemplate + "\\Views\\Index.txt");

            try
            {
                maskString2 = maskString2.Replace("MASK", className);
                string className1 = char.ToLower(className[0]) + className.Substring(1, className.Length - 1);
                maskString2 = maskString2.Replace("mask", className1);
                maskString2 = maskString2.Replace("TABLENAME", tableName);

                File.WriteAllText(pathToWrite + "\\View\\" + className + "\\Index.aspx", maskString2);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }
    }
}
